package com.lagou.session_quickstart;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SetSession extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 将需要共享的数据存到session中
        // 1、获取到session对象
        HttpSession session = req.getSession();
        // 2、通过session对象进行数据存入
        session.setAttribute("name", "哈哈，呵呵");
        System.out.println("当前已将共享数据存入session！");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
